<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="format-detection" content="telephone=no" />
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    <link rel="stylesheet" href="stylesheets/zui.min.css"/>
    <link rel="stylesheet" href="stylesheets/main.css" id="css"/>
    <script src="javascripts/jquery-1.10.1.min.js"></script>
    <script src="javascripts/main.js"></script>
    <script src="javascripts/footer.js"></script>
    <script src="javascripts/replayCode.js"></script>
    <title>斯迈普解盘侠</title>
    <style type="text/css">
    	.getCodeButton {
    		border:0px;
    		width:100%;
    		height:100%;
    		text-align:center;
    		background-color:#e24344;
    		color:white;
    	}
    </style>
    <script type="text/javascript">
    var c ;
    	$(function(){
    		
    		//验证码
	    	var a = parseInt(Math.random()*10) ;
	    	var b = parseInt(Math.random()*10) ;
	    	c = a +b;
	    	$('#code').html(a + '+' + b + '=?');	
    		var timer = null;//定时器
    		
    		var showMsgFun = function(msg){
    			$('.pageMsg').text(msg);
    		};
    		/**
    			绑定发送手机短信验证码事件
    		*/
    		$('#getCodeBtn').click(function(){
    			var $getCodeBtn = $(this);
    			var mphone = $('input[name="mphone"]').val();
    			if(!/^[0-9]{11}$/.test(mphone)){
    				showMsgFun('输入手机号码不符合');
    				return;
    			}
    			
    			
    			/* var r = $('#numCode').val();
    			if(r != c){
    				showMsgFun('请输入正确的答案');
    				return;
    			} */
    			$.ajax({
    				url:'../member/sendSMSValidCode.do',
    				type:'post',
    				dataType:'json',
    				data:{
    					mphone:mphone
    				},
    				success:function(d){
    					if(d.success){
    						$getCodeBtn.attr('disabled','disabled');
    						var s = 60;
    						var timeout = false; //启动及关闭按钮  
    						var time = function()  
    						{  
    						   if(timeout) return;  
    						   if(s != -1){
    							   //showMsgFun('发送成功，'+s+'秒后重新发送。');
    							   showMsgFun('');
    							   $getCodeBtn.text(s+'秒后重新发送').css({color:'#666666'});
	  							} else {
	  								//showMsgFun('如果未收到短信，请尝试重新获取。');
	  								$getCodeBtn.text('重新获取').css({color:'white'}).removeAttr('disabled');
	  								timeout = true;
	  							}
	  							s--;  
	  							timer = setTimeout(time,1000); //time是指本身,延时递归调用自己,100为间隔调用时间,单位毫秒  
    						} 
    						time();
    						
    					} else {
    						showMsgFun(replayCode[d.statusCode]);
    					}
    				}
    			});
    		});
    		
    		var registSubmitFun = function(){
    			var mphone = $('input[name="mphone"]').val();
    			var smsValidCode = $('input[name="smsValidCode"]').val();
    			var email = $('input[name="email"]').val();
    			var pwd = $('input[name="pwd"]').val();
    			var repwd = $('input[name="repwd"]').val();
    			var nick = $('input[name="nick"]').val();
    			//验证数据信息不能为空
    			if($.trim(mphone) == ''){
    				showMsgFun('手机号码不能为空！');
    				return;
    			}
    			if($.trim(smsValidCode) == ''){
    				showMsgFun('验证码不能为空！');
    				return;
    			}
    			if($.trim(email) == ''){
    				showMsgFun('我的邮箱不能为空！');
    				return;
    			}else if(!/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/.test($.trim(email))){
    				showMsgFun('邮箱格式不正确！');
    				return;
    			}
    			if($.trim(pwd) == '' || $.trim(repwd) == ''){
    				showMsgFun('密码、确认密码不能为空！');
    				return;
    			}
    			if(pwd != repwd){
    				showMsgFun('两次密码不一致！');
    				return ;
    			}
    			if($.trim(nick) == ''){
    				showMsgFun('昵称不能为空！');
    				return;
    			}
    			
    			$.ajax({
    				url:'../member/regist.do',
    				type:'post',
    				dataType:'json',
    				data:{
    					mphone:mphone,validCode:smsValidCode,email:email,pwd:pwd,nick:nick
    				},
    				success:function(d){
    					if(d.success){
    						if(timer){
    							clearTimeout(timer);
    						}
    						showMsgFun('注册成功，等待跳转...');
    						setTimeout(function(){
    							window.location.href = 'login.html';
    						},3000);
    					} else {
    						showMsgFun(replayCode[d.statusCode]);
    					}
    				}
    			});
    		};
    		
    		//邦迪注册按钮事件
    		$('.registBtn').click(function(){
    			registSubmitFun();
    		});
    	});
    </script>
</head>
<body class="index">
<div class="container main">
    <div class="row messages-box reg-box">
        <div class="col-xs-12">
            <table class="table">
                <tbody>
                <tr>
                    <td><img src="images/12.png" alt=""/></td>
                    <td colspan="2"><input type="tel" name="mphone" placeholder="手机号码"/></td>
                </tr>
                
             <!--    <tr>
                    <td ><span id="code" style="color: firebrick;"></span></td>
                    <td><input type="text" id='numCode'name="numCode" placeholder="请输入正确的答案"/></td>
                </tr> -->
                <tr>
                    <td class="code-icon"><i class="icon icon-envelope"></i></td>
                    <td><input type="text"  name="smsValidCode" placeholder="验证码"/></td>
                    <td class="send-code-box get-code-btn" style="font-size:1rem;padding:0px;">
                    	<button id="getCodeBtn" class="getCodeButton">发送验证码</button>
                    </td>
                </tr>
                <tr>
                    <td><img src="images/13.png" alt=""/></td>
                    <td colspan="2"><input type="email" name="email" placeholder="我的邮箱"/></td>
                </tr>
                <tr>
                    <td><img src="images/14.png" alt=""/></td>
                    <td colspan="2"><input type="password" name="pwd" placeholder="密码"/></td>
                </tr>
                <tr>
                    <td></td>
                    <td colspan="2"><input type="password" name="repwd" placeholder="确认密码"/></td>
                </tr>
                <tr>
                    <td><img src="images/15.png" alt=""/></td>
                    <td colspan="2"><input type="text" name="nick" placeholder="昵称"/></td>
                </tr>
                
                <tr>
                    <td></td>
                    <td ></td>
                </tr>
                </tbody>
            </table>
            <div class="row login-btn-box">
	            <div class="col-xs-12">
	                <button class="btn btn-danger registBtn">注册</button>
	            </div>
	        </div>
            <div class="row login-btn-box">
	            <div class="col-xs-12">
	                <label class="pageMsg"></label>
	            </div>
	        </div>
        </div>
    </div>

   <footer class="nav-footer">
			<div class="col-xs-3" id="hall" >
				<i class="icon icon-home"></i>
				<h4>解盘</h4>
			</div>
			<div class="col-xs-3" id="notify"  >
				<i class="icon icon-volume-up"></i>
				<h4>喊单</h4>
			</div>
			<div class="col-xs-3" id= "news" >
				<i class="icon icon-globe"></i>
				<h4>资讯</h4>
			</div>
			<div class="col-xs-3  footer-nav-active" id="my" >
				<i class="icon icon-user"></i>
				<h4>个人中心</h4>
			</div>
</footer>
</div>

</body>
</html>